package com.example.peibei.ui.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.dingtao.common.bean.Order;
import com.dingtao.common.util.GlideUtils;
import com.example.peibei.R;

import java.util.List;

public class MyBillListAdapter extends BaseQuickAdapter<Order.RecordsDTO, BaseViewHolder> {

    public MyBillListAdapter(@Nullable List<Order.RecordsDTO> data) {
        super(R.layout.item_my_bill, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, Order.RecordsDTO item) {
        ImageView head = helper.getView(R.id.iv_head);
        Glide.with(getContext()).load(item.getImageUrl()).apply(RequestOptions.bitmapTransform(new CircleCrop())).into(head);
        helper.setText(R.id.tv_name, item.getNickName()).setText(R.id.tv_address, "来自" + item.getArea()).setText(R.id.tv_dec,item.getOtherDesc());
        if ("0".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"/小时");
        }else if ("1".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"/天");
        }else if("-1".equals(item.getUnit())){
            helper.setText(R.id.tv_unit,"￥一口价");
        }
        if (item.getPrice().contains(".")){
            String[] split = item.getPrice().split("\\.");
            helper.setText(R.id.tv_price,split[0]);
        }else{
            helper.setText(R.id.tv_price,item.getPrice());
        }
        List<String> imgs = item.getImgs();
        LinearLayout llImgs = helper.getView(R.id.ll_imgs);
        ImageView imgOne = helper.getView(R.id.iv_img_one);
        ImageView imgTwo = helper.getView(R.id.iv_img_two);
        ImageView imgThree = helper.getView(R.id.iv_img_three);
        if (imgs.size() > 0) {
            llImgs.setVisibility(View.VISIBLE);
            if (imgs.get(0) != null && !imgs.get(0).equals("")) {
                imgOne.setVisibility(View.VISIBLE);
                GlideUtils.loadImg(getContext(),imgs.get(0),20,imgOne);
            }else{
                imgOne.setVisibility(View.INVISIBLE);
            }
            if (imgs.size() > 1 && imgs.get(1) != null && !imgs.get(1).equals("")) {
                imgTwo.setVisibility(View.VISIBLE);
                GlideUtils.loadImg(getContext(),imgs.get(1),20,imgTwo);
            }else{
                imgTwo.setVisibility(View.INVISIBLE);
            }
            if (imgs.size() > 2 &&imgs.get(2) != null && !imgs.get(2).equals("")) {Glide.with(getContext()).load(imgs.get(2)).into(imgThree);
                imgThree.setVisibility(View.VISIBLE);
                GlideUtils.loadImg(getContext(),imgs.get(2),20,imgThree);
            }else{
                imgThree.setVisibility(View.INVISIBLE);
            }
        } else {
            llImgs.setVisibility(View.GONE);
        }
    }
}
